﻿jQuery.fn.validCPF = function(a) { var b = this; var c = b.val().replace('.', '').replace('.', '').replace('-', ''); if (c.length != 11) { return false } else { var d = /1{11}|2{11}|3{11}|4{11}|5{11}|6{11}|7{11}|8{11}|9{11}|0{11}/; if (d.test(c)) { return false } else { var x = 0; var y = 0; var e = 0; var f = 0; var g = 0; var h = ""; var k = ""; var l = c.length; x = l - 1; for (var i = 0; i <= l - 3; i++) { y = c.substring(i, i + 1); e = e + (y * x); x = x - 1; h = h + y } f = 11 - (e % 11); if (f == 10) { f = 0 } if (f == 11) { f = 0 } k = c.substring(0, l - 2) + f; x = 11; e = 0; for (var j = 0; j <= (l - 2); j++) { e = e + (k.substring(j, j + 1) * x); x = x - 1 } g = 11 - (e % 11); if (g == 10) { g = 0 } if (g == 11) { g = 0 } if ((f + "" + g) == c.substring(l, l - 2)) { return true } else { return false } } } };